class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> val;

        for (int i = 0; i < tokens.size(); i++) {
            string s = tokens[i];

            if (s == "+" || s == "-" || s == "*" || s == "/") {
                int r = val.top();
                val.pop();
                int l = val.top();
                val.pop();

                if (s == "+") {
                    val.push(l + r);
                    continue;
                }
                if (s == "-") {
                    val.push(l - r);
                    continue;
                }
                if (s == "*") {
                    val.push(l * r);
                    continue;
                }
                if (s == "/") {
                    val.push(l / r);
                }
            } else {
                val.push(stoi(s));
            }
        }
        return val.top();
    }
};
